package com.smartao.base.menu;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.ForeignKey;

import com.smartao.base.module.Module;
import com.smartao.core.orm.entity.BaseEntity;

/**
 * 菜单实体类
 * @author Ricky
 */
@Entity
@Table(name = "T_BASE_MENU")
public class Menu extends BaseEntity<Menu> {

	private static final long serialVersionUID = -8999718195890657344L;
	
	private static final String BLANK_URL = "javascript:;";
	
	public Menu() {
		super();
	}
	
	public Menu(String name, MenuType menutype) {
		super();
		this.name = name;
		this.menutype = menutype;
	}
	
	public Menu(String name, MenuType menutype, Menu parent) {
		super();
		this.name = name;
		this.menutype = menutype;
		this.parent = parent;
	}

	private String name;
	// 菜单类型
	@Enumerated(EnumType.STRING)
	private MenuType menutype;
	
	@ManyToOne
	@ForeignKey(name = "none")
	@JoinColumn(name = "parent")
	@Fetch(FetchMode.JOIN)
	private Menu parent;
	
	//菜单所属模块
	@ManyToOne
	@ForeignKey(name = "none")
	@JoinColumn(name = "module")
	@Fetch(FetchMode.JOIN)
	private Module module;
	private String url;
	private String img;
	private String style;
	private int dsporder=1;
	private String description;
	
	private boolean visible = true;
	private int childCount=0;
	
	@Transient
	private List<Menu> children;

	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public MenuType getMenutype() {
		return menutype;
	}

	public void setMenutype(MenuType menutype) {
		this.menutype = menutype;
	}

	public Menu getParent() {
		return parent;
	}

	public void setParent(Menu parent) {
		this.parent = parent;
	}

	public Module getModule() {
		return module;
	}

	public void setModule(Module module) {
		this.module = module;
	}

	public String getUrl() {
		return url;
	}
	
	
	public String getLink() {
		return url == null ? BLANK_URL : url;
	}
	public void setUrl(String url) {
		this.url = url;
	}

	public String getImg() {
		return img;
	}

	public void setImg(String img) {
		this.img = img;
	}

	public String getStyle() {
		return style;
	}

	public void setStyle(String style) {
		this.style = style;
	}

	public int getDsporder() {
		return dsporder;
	}

	public void setDsporder(int dsporder) {
		this.dsporder = dsporder;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	public int getChildCount() {
		return childCount;
	}

	public void setChildCount(int childCount) {
		this.childCount = childCount;
	}
	
	public boolean getIsParent() {
		return this.childCount>0;
	}

	public List<Menu> getChildren() {
		return children;
	}
	
	public boolean getHasChild() {
		return childCount>0;
	}
	
	public boolean getChecked(){
		return visible;
	}

	public void setChildren(List<Menu> children) {
		this.children = children;
	}
	
}
